﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data;
using Crosland.Framework.DataHelper;
using Crosland.Framework.Base;
using Crosland.Offline.Core;
using Crosland.Offline.Data.Helper;

namespace Crosland.Offline.Data.Dao
{
    public class InterlocutoresDao : DaoBase
    {
        public InterlocutoresDao(string strConn): base(strConn)
        {
        }

        InterlocutoresHelper helper = new InterlocutoresHelper();

        public int Save(Interlocutores entity)
        {
            DbCommand command = dbProvider.GetStoredProcCommand(helper.SpSave);

            dbProvider.AddInParameter(command, helper.Kunnr, DbType.String, entity.Kunnr);
            dbProvider.AddInParameter(command, helper.Vkorg, DbType.String, entity.Vkorg);
            dbProvider.AddInParameter(command, helper.Vtweg, DbType.String, entity.Vtweg);
            dbProvider.AddInParameter(command, helper.Spart, DbType.String, entity.Spart);
            dbProvider.AddInParameter(command, helper.Parvw, DbType.String, entity.Parvw);
            dbProvider.AddInParameter(command, helper.Kunn2, DbType.String, entity.Kunn2);

            return dbProvider.ExecuteNonQuery(command);
        }

        public List<Interlocutores> GetByCriteria(string codCli)
        {
            List<Interlocutores> entitys = new List<Interlocutores>();
            DbCommand command = dbProvider.GetStoredProcCommand(helper.SpGetByCriteria);
            dbProvider.AddInParameter(command, helper.Kunnr, DbType.String, codCli);

            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    entitys.Add(helper.Create(dr));
                }
            }

            return entitys;
        }
    }
}
